using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using Zwms.Data.BusinessObjects;
using Zwms.Data.Base;

namespace Zwms.Data.ManagerObjects
{
    public partial interface ISysMenuManager : IManagerBase<Zwms.Data.BusinessObjects.SysMenu, string>
    {
        // Get Methods
        SysMenu GetById(System.String roleCode, System.String moduleCode, System.String menuCode);
        IList<SysMenu> GetMenuByRoleCode(string sRoleCode);
    }

    partial class SysMenuManager : ManagerBase<Zwms.Data.BusinessObjects.SysMenu, string>, ISysMenuManager
    {
        #region Constructors

        public SysMenuManager()
            : base()
        {
        }
        public SysMenuManager(INHibernateSession session)
            : base(session)
        {
        }

        #endregion

        #region Get Methods

        public override SysMenu GetById(string id)
        {
            string[] keys = id.Split('^');

            if (keys.Length != 3)
                throw new Exception("Invalid Id for SysMenuManager.GetById");

            return GetById(keys[0], keys[1], keys[2]);
        }
        public SysMenu GetById(System.String roleCode, System.String moduleCode, System.String menuCode)
        {
            ICriteria criteria = Session.GetISession().CreateCriteria(typeof(SysMenu));

            criteria.Add(NHibernate.Criterion.Expression.Eq("RoleCode", roleCode));
            criteria.Add(NHibernate.Criterion.Expression.Eq("ModuleCode", moduleCode));
            criteria.Add(NHibernate.Criterion.Expression.Eq("MenuCode", menuCode));

            SysMenu result = (SysMenu)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
        }

        public IList<SysMenu> GetMenuByRoleCode(string sRoleCode)
        {
            ICriteria criteria = Session.GetISession().CreateCriteria(typeof(SysMenu));

            criteria.Add(NHibernate.Criterion.Expression.Eq("RoleCode", sRoleCode));

            IList<SysMenu> result = criteria.List<SysMenu>();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
        }


        #endregion
    }
}